import React from 'react'
// ===================================================================== global declare
const { $fn, $async } = window
// ===================================================================== global antd

// ===================================================================== global template

// ===================================================================== private template
const Page = $async(()=>import('#tp/page-content'))
// ===================================================================== private component
const Table = $async(()=>import('#cpt/table'))
// ===================================================================== config declare

// ===================================================================== component
export default class extends React.Component{
	state = {
		pag: {},
		data:[],
		selectedKeys:[],
		ids:[],
		btns : [
			{ label:'打印', disabled:true,  onClick:() => {
				const ids = this.state.selectedKeys.map(v=>v.id)
				window.open(window.$config.api + 'report/print?id=' + ids)
			} },
			{ label:'推送到查询平台', disabled:true, onClick:() => {} },
			{ label:'补报告单', disabled:true, onClick:() => {} },
			{ label:'报告单终止', disabled:true, onClick:() => {} },
			{ label:'报告单删除', disabled:true, onClick:() => {} },
		],
	}
	// 禁用按钮
	disBtns = () => {
		const { btns } = this.state
		btns.forEach(v=> v.disabled = true)
		this.setState({btns})
	}
	
	componentDidMount(){
		this.fetch()
	}
	model = {}
	// paging
	fetch = param => $fn.fetch.call(this,'report/index', param)
	// select

	
	cols = [
		{ type:'checkbox' },
		{ title: '编号', 		field: 'spec_num', 		width:160, align:'tc' },
		{ title: '标本条码', 	field: 'spec_code', 	width:150, align:'tc' },
		{ title: '受检人姓名', 	field: 'patient_name', 	width:150 },
		{ title: '版本号', 		field: 'tmpl_vs', 		width:100 },
		{ title: '报告单模板', 	field: 'tmpl_name', 	width:300 },
		{ title: '所属医院', 	field: 'hosp_name', 	width:250 },
		{ title: '所属派送人', 	field: 'salesman_name', width:100 },
		
		{ title: '生成时间', 	field: 'created_at', 	width:150, align:'tc' },
		{ title: '派送完成时间', field: 'update_at', 	width:150, align:'tc'},
	]
	
	render(){
		const { btns, data, pagingLoading, pag } = this.state
		return (
			<Page title='报告单' btns={btns}>
				<Table 
					cols			= { this.cols }
					data 			= { data }
					loading 		= { pagingLoading }
					onRow			= { selectedKeys => {
						this.setState({ selectedKeys },()=>{
							if($fn.hasArray(this.state.selectedKeys)){
								btns.forEach(v=> v.disabled = false)
								this.setState({btns})
							}else{
								this.disBtns()
							}
						})
					} }
					pag				= { pag }
					onChange		= { (current, pageSize) => $fn.pageChange.call(this,{current, pageSize}) }
				/>
			</Page>
		)
	}
}